package store

import (
	"go_gvm_mini/instructions/base"
	"go_gvm_mini/rtda"
)

type LSTORE struct {
	base.Index8Instruction
}

func (self *LSTORE) Execute(jFrame *rtda.JFrame) {
	_lstore(jFrame, self.Index)
}

type LSTORE_0 struct {
	base.NoOperandsInstruction
}

func (self *LSTORE_0) Execute(jFrame *rtda.JFrame) {
	_lstore(jFrame, 0)
}

type LSTORE_1 struct {
	base.NoOperandsInstruction
}

func (self *LSTORE_1) Execute(jFrame *rtda.JFrame) {
	_lstore(jFrame, 1)
}

type LSTORE_2 struct {
	base.NoOperandsInstruction
}

func (self *LSTORE_2) Execute(jFrame *rtda.JFrame) {
	_lstore(jFrame, 2)
}

type LSTORE_3 struct {
	base.NoOperandsInstruction
}

func (self *LSTORE_3) Execute(jFrame *rtda.JFrame) {
	_lstore(jFrame, 3)
}

func _lstore(frame *rtda.JFrame, index uint) {
	val := frame.OperandStack().PopLong()
	frame.LocalVars().SetLong(index, val)
}
